package com.xiaobaibai.server.label;

import com.xiaobaibai.dao.BlogDao;
import com.xiaobaibai.dao.LabelDao;
import com.xiaobaibai.pojo.Label;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LabelServiceImpl implements ILabelService{

    @Autowired
    private LabelDao labelDao;

    @Autowired
    private BlogDao blogDao;

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Override
    public List<Label> getLabelList() {
        return labelDao.getAllLabel();
    }

    @Override
    public Label addLabel(String title) {
        Label label=new Label();
        label.setTitle(title);
        labelDao.insertSelective(label);
        stringRedisTemplate.delete("AllLabel");
        return label;
    }

    @Override
    public boolean delLabel(Integer id) {
        int i = blogDao.haveLabelId(id);
        if(i!=0)
            return false;
        labelDao.deleteByPrimaryKey(id);
        stringRedisTemplate.delete("AllLabel");
        return true;
    }

}